package com.bignerdranch.android.expresshelper.Activity;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.print.PrintHelper;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.View;

import com.bignerdranch.android.expresshelper.Adapter.HistoryAdapter;
import com.bignerdranch.android.expresshelper.Bean.ExpressBean;
import com.bignerdranch.android.expresshelper.Dao.ExpressDao;
import com.bignerdranch.android.expresshelper.R;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Administrator on 2016/7/6.
 */
public class WarningDialog extends DialogFragment {

    private ExpressDao mDao;
    private List<ExpressBean> mDate;



    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mDao = new ExpressDao(getActivity().getApplicationContext());
        mDate = mDao.queryAll();

    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        Dialog dialog = new AlertDialog.Builder(getActivity())
                .setTitle(R.string.warning)
                .setMessage(R.string.message)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mDao.deleteAll();
                        mDate.clear();
                      /*  Bundle bundle = new Bundle();
                        bundle.putSerializable("date",(Serializable) mDate);
                        setArguments(bundle);

                        Log.e("---mDate-->>",mDate.size()+"");
*/
                    }
                })
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                       // mDate = null;

                    }
                })
                .create();
            Message message = new Message();
            message.what = 0;
            message.obj=mDate;
            dialog.setDismissMessage(message);




        return dialog;
    }
}
